package burp;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;


/**
 * Created by shuaidong on 2017/6/24.
 */
public class Context {
    public static Properties properties = null;

    public static String tmpFileFolderReq = null;

    public static List<String> tmpFilenameList;

    public static int size;

    static {
        properties = new Properties();
        try {
            properties.load(Context.class.getClassLoader().getResourceAsStream("config.properties"));

        } catch (IOException e) {
            e.printStackTrace();
        }
        if (Os.checkOs() == Os.OsType.MAC){
            tmpFileFolderReq = properties.getProperty("tmpFileFolderReq","/tmp/sqlmap");
        }

        if (Os.checkOs() == Os.OsType.WINDOWS){
            tmpFileFolderReq = properties.getProperty("tmpFileFolderReq","sqlmapTmp");
        }

        tmpFilenameList = null;
    }



   public static List<String> getTmpFilenameTmp(boolean IsCreate,int size){
       if (tmpFilenameList==null||IsCreate){

           long ms = System.currentTimeMillis();

           String tmpFilename = tmpFileFolderReq + "/" + ms + ".req";
           Context.size = size;
           tmpFilenameList = new ArrayList<String>();

          for (int i=0;i<size;i++){
              tmpFilenameList.add(tmpFilename);

              tmpFilename = tmpFileFolderReq + "/" + ms+1 + ".req";
          }

           return tmpFilenameList;
       }
       return tmpFilenameList;
   }
   public static void  writeResourceConfig(String key,String value,String comment){
       String path = Context.class.getResource("/config.properties").getPath();
       try {
           FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
           properties.setProperty(key,value);
           properties.store(fileOutputStream,comment);
           fileOutputStream.close();
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }
   }




}
